Skip to content

NH-2285 - Support for LockMode in Linq provider #530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 2, 2018

Conversation

oskarb
Copy link
Member

@oskarb oskarb commented Nov 20, 2016

This is a rebased and updated version of PR #304 to implement support for setting lock mode on LINQ queries.

A notable difference is that the provided test cases have been improved to verify that the locking actually happens. This seems to show that they in fact do NOT take effect on certain dialects (at least MSSQL2008) when paging is also used. That may not be a flaw of this patch though, perhaps it's a deeper problem that affects HQL too?

Fixes #968

@oskarb oskarb added this to the 5.0.0 milestone Nov 20, 2016
@oskarb
Copy link
Member Author

oskarb commented Nov 20, 2016

@hazzik What would be the way to fix the caching issue exposed by QueryLock.CanChangeLockModeForQuery()?

@oskarb
Copy link
Member Author

oskarb commented Nov 20, 2016

It seems the locking is not applied when paging is also used in the query on MSSQL 2008 dialect.

@hazzik
Copy link
Member

hazzik commented Dec 4, 2016

I don't think that any of the databases support locking with paging.

@gliljas
Copy link
Member

gliljas commented Dec 4, 2016

I'd like to throw in this old thread into the discussion:
https://groups.google.com/d/topic/nhibernate-development/XqhDhDrILhc/discussion

@gliljas
Copy link
Member

gliljas commented Jan 4, 2017

I'll have another go at this.

@hazzik hazzik modified the milestones: 5.0, 5.1 Sep 1, 2017
@hazzik hazzik modified the milestones: 5.1, 6.0 Dec 23, 2017
@hazzik hazzik force-pushed the NH-2285-v2 branch 2 times, most recently from 74f6937 to 9bc4e6a Compare November 26, 2018 07:31
@hazzik hazzik modified the milestones: 6.0, 5.2 Nov 26, 2018
@hazzik hazzik changed the title NH-2285 - Support for LockMode in linq provider (replaces #304) NH-2285 - Support for LockMode in Linq provider Nov 26, 2018
Copy link
Member

@fredericDelaporte fredericDelaporte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SQLite does not seem to support a locking mechanism. Its dialect does override Dialect.ForUpdateString to an empty string and does not overrides locking methods to supply an alternative way of locking.

Firebird accepts for update in its syntax but does not do much of it, as explained in its documentation. So in effect it does not actually lock the row. For this, the with lock clause should be used in Firebird, but they strongly advise against it. And its current NHibernate dialect does not use it.

So it seems to me we need an additional TestDialect property for stating if locking row is supported by the dialect, and if not, disable the AssertSeparateTransactionIsLockedOut check. (Or maybe disable the whole fixture.)

Copy link
Member

@fredericDelaporte fredericDelaporte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

using (var s2 = OpenSession())
using (s2.BeginTransaction())
{
// TODO: We should try to verify that the exception actually IS a locking failure and not something unrelated.
Copy link
Member

@fredericDelaporte fredericDelaporte Nov 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better, but it does not seem critical to me.

@fredericDelaporte

This comment has been minimized.

@hazzik

This comment has been minimized.

@hazzik

This comment has been minimized.

OnurGumus and others added 2 commits November 29, 2018 10:37
- Add test case to verify that a change in lock mode will avoid reusing cached query.
hazzik
hazzik previously approved these changes Nov 28, 2018
hazzik
hazzik previously approved these changes Nov 28, 2018
- Rename SetLockMode to WithLock
- Add overload to support locking on collections in the query
- Restrict tests only to dialects that do support locks
- Ignore paging tests if dialect does not support combining locks with paging
@fredericDelaporte
Copy link
Member

@hazzik, I am not merging this as I do not know how you intent this to be merged. I would tend to squash and add Oskar and you as co-authors, but as you have rebased this to three commits, I wonder if you were willing to merge this as-is.

@hazzik
Copy link
Member

hazzik commented Dec 2, 2018

I'm just not sure who will be the main author of the commit when it's got squashed: the PR is made by Oskar with the changes originated from Onur.

@fredericDelaporte
Copy link
Member

It would surprise me if it will not be the first commit author, so Onur.

@fredericDelaporte
Copy link
Member

Well looking into a past example, #1492 merging seems to have taken into account the PR author, not the first commit author. It is the same for #460. So the author would be Oskar in fact.

@hazzik
Copy link
Member

hazzik commented Dec 2, 2018

Yes, I was going to investigate this first (what you've already done).

@hazzik hazzik merged commit 67a0064 into nhibernate:master Dec 2, 2018
@hazzik hazzik added the r: Fixed label Dec 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants